package com.matrix.common.context;

/**
 * @author 有点甜
 * @since 2025/8/5
 */
public class UserContext {
    private static final ThreadLocal<Long> USER_ID_HOLDER = new ThreadLocal<>();
    private static final ThreadLocal<String> USER_ROLE_HOLDER = new ThreadLocal<>();

    public static void setUserId(Long userId) {
        USER_ID_HOLDER.set(userId);
    }
    public static Long getUserId() {
        return USER_ID_HOLDER.get();
    }

    public static void setUserRole(String userRole) {
        USER_ROLE_HOLDER.set(userRole);
    }

    public static String getUserRole() {
        return USER_ROLE_HOLDER.get();
    }

    public static void clear() {
        USER_ID_HOLDER.remove();
        USER_ROLE_HOLDER.remove();
    }
}